import request from "@/utils/request";
import type { RoleResponseData, Records, MenuResponseData } from "./type";
enum API {
  // 获取角色分页列表
  ALLROLE_URL = "/admin/acl/role/",
  //新增
  ADDROLE_URL = "/admin/acl/role/save",
  //修改
  UPDATEROLE_URL = "/admin/acl/role/update",
  //获取全部的菜单与按钮的数据
  ALLPERMISSION_URL = "/admin/acl/permission/toAssign/",
  //给相应的职位分配权限
  SETPERMISSION_URL = "/admin/acl/permission/doAssign/?",
  //删除角色
  DELETEROLE_URL = "/admin/acl/role/remove/",
}
// 获取角色分页列表
export const reqAllRole = (page: number, limit: number) =>
  request.get<any, RoleResponseData>(API.ALLROLE_URL + `${page}/${limit}`);
//新增和修改
export const reqAddRoleOrUpdate = (data: Records) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEROLE_URL, data);
  } else {
    return request.post<any, any>(API.ADDROLE_URL, data);
  }
};
//获取全部的菜单与按钮的数据
export const reqAllPermission = (roleId: number) =>
  request.get<any, MenuResponseData>(API.ALLPERMISSION_URL + roleId);
//给相应的职位分配权限
export const reqSetPermission = (roleId: number, permissionId: number[]) =>
  request.post(
    API.SETPERMISSION_URL + `roleId=${roleId}&permissionId=${permissionId}`
  );
//删除角色
export const reqDeleteRole = (roleId: number) =>
  request.delete<any, any>(API.DELETEROLE_URL + roleId);
